package com.caocaog.market.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.entity.InformationReply;
import com.caocaog.market.service.InformationReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.GenericController;
import org.jeecg.common.system.domain.QueryRequest;
import org.jeecg.common.system.query.PageGenerator;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 内容回复
 *
 * @author chechen
 * @date 2021-11-13
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(value = "information", tags = InformationReplyController.TABLE_MEANING)
@RequestMapping("/informationReply")
public class InformationReplyController extends GenericController<InformationReply, InformationReplyService> {

    public static final String TABLE_MEANING = "内容回复";

    private static final String PAGE = "内容回复-分页列表查询";
    @ApiOperation(value = PAGE, notes = PAGE)
    @GetMapping(value = "/list")
    @RequiresPermissions("informationReply:view")
    public Result<?> queryPageList(InformationReply informationReply, QueryRequest queryRequest) {
        Page<InformationReply> page = PageGenerator.createPageSort(queryRequest);
        IPage<InformationReply> pageList = super.service.queryInformationReplyPage(page, informationReply);
        return Result.OK(pageList);
    }

    private static final String ADD = "内容回复-添加";
    @AutoLog(value = ADD)
    @ApiOperation(value = ADD, notes = ADD)
    @PostMapping(value = "/add")
    @RequiresPermissions("informationReply:add")
    public Result<?> add(@RequestBody InformationReply informationReply) {
        return Result.OK(ADD_SUCCESS, super.service.addInformationReply(informationReply));
    }

    private static final String DELETE = "内容回复-通过id删除";
    @AutoLog(value = DELETE)
    @ApiOperation(value = DELETE, notes = DELETE)
    @DeleteMapping(value = "/delete")
    @RequiresPermissions("informationReply:delete")
    public Result<?> delete(@RequestParam(name = "id") String id) {
        int count = super.service.deleteInformationReplyById(id);
        return Result.OK(DELETE_SUCCESS, count);
    }

    private static final String DELETE_BATCH = "内容回复-批量删除";
    @AutoLog(value = DELETE_BATCH)
    @ApiOperation(value = DELETE_BATCH, notes = DELETE_BATCH)
    @DeleteMapping(value = "/deleteBatch")
    @RequiresPermissions("informationReply:delete")
    public Result<?> deleteBatch(@RequestParam(name = "ids") String ids) {
        int count = super.service.deleteBatchInformationReplyByIds(Arrays.asList(ids.split(",")));
        return Result.OK(DELETE_SUCCESS, count);
    }

}
